const {
	Service
} = require('uni-cloud-router')
const dbHelper = require('db-helper')

module.exports = class CashAccountService extends Service {
	async getAccountByUid(uid, transaction) {
		let account = await dbHelper.getOne("t3ds-account", {
			userId: uid
		})
		if (!account) {
			account = {
				userId: uid,
				balance: 0,
				frozen: 0,
				settle: 0,
				total: 0
			}
			await dbHelper.insert("t3ds-account", account)
		}
		if (transaction) {
			account = dbHelper.getById("t3ds-account", account._id, transaction)
		}
		return account
	}
}
